package org.nbict.iot.protocol.task;

import org.apache.storm.trident.state.map.IBackingMap;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Created by songseven on 18/6/25.
 */
public class OutBreakTrendBackingMap implements IBackingMap<Long> {
    Map<String, Long> storage = new ConcurrentHashMap<String, Long>();

    @Override
    public List<Long> multiGet(List<List<Object>> keys) {
        List<Long> values = new ArrayList<Long>();
        for (List key : keys) {
            Long value = storage.get(key.get(0));
            if (value == null) {
                values.add(new Long(0));
            }else {
                values.add(value);
            }
        }
        return values;
    }

    @Override
    public void multiPut(List<List<Object>> keys, List<Long> vals) {

        for (int i = 0; i < keys.size(); i++) {
            storage.put((String)keys.get(i).get(0), vals.get(i));
        }
    }
}
